﻿using CPPEI;
using CPPEI.WebApi;
using SLG.Domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Ser = SLG.Domain.Services;
using Ent = SLG.Domain.Entities;

namespace SLG.WebApi.Data
{
    /// <summary>
    /// 获得服务器列表
    /// </summary>
    [AuthGetAction("Config", "GetServers", "1.0")]
    public class GetServersAction : BaseAction<GetServersParams, GetServersResult>
    {
        protected override ActionResult<GetServersResult> OnExecute(ActionContext context, SysParameters sysParams, GetServersParams opParams)
        {
            Ser.BDService service = new Ser.BDService();

            GetServersResult actResult = new GetServersResult();
            for (int index = 0; index < 1; index++)
            {
                GetServersResult.Item item = new GetServersResult.Item();
                item.Id = index + 1;
                item.Caption = string.Format("本地测试服务器-{0}", index + 1);
                item.Status = 1;
                item.Url = "http://localhost:4176/";
                item.PlayerCount = index * 100;

                actResult.Items.Add(item);
            }
            return new ActionResult<GetServersResult>(actResult);

            /*
            ListResult<Ent.BD_Race> serResult = service.GetServers();

            if (serResult.IsSuccess)
            {
                GetServersResult actResult = new GetServersResult();

                for (int index = 0; index < serResult.Data.Count; index++)
                {
                    GetServersResult.Item item = new GetServersResult.Item();
                    item.Id = serResult.Data[index].Id;
                    item.Caption = serResult.Data[index].Caption;
                    item.ResPath = serResult.Data[index].ResPath;

                    actResult.Items.Add(item);
                }
                return new ActionResult<GetServersResult>(actResult);
            }
            else
            {
                return new ActionResult<GetServersResult>(serResult);
            }*/
        }
    }

    public class GetServersParams
    {
    }

    public class GetServersResult
    {
        public List<Item> Items = new List<Item>();

        public class Item
        {
            public int Id { get; set; }

            public string Caption { get; set; }

            /// <summary>
            /// 服务器的地址
            /// </summary>
            public string Url { get; set; }

            public int Status { get; set; }

            public int PlayerCount { get; set; }
        }
    }
}
